package org.tobuy.dao.proxy;
import java.util.ArrayList;
import java.util.List;

import org.tobuy.dao.IUserDAO;
import org.tobuy.dao.impl.UserDAOImpl;
import org.tobuy.dbc.DatabaseConnection;
import org.tobuy.vo.User;

public class UserDAOProxy implements IUserDAO{
	private DatabaseConnection dbc= null;
	private IUserDAO dao = null; //problem?
	public UserDAOProxy(){
		try{
			this.dbc = new DatabaseConnection();
		}catch(Exception e){
			e.printStackTrace();
		}
		this.dao = new UserDAOImpl(dbc.getConnection());
	}

	public boolean findLogin(User user) throws Exception {
		boolean flag = false;
		try{
			flag = this.dao.findLogin(user);
		}catch(Exception e){
			throw e;
		}finally{
			this.dbc.close();
		}
		return flag;
	}
	public List<User> findUser() throws Exception {
		List<User> users = new ArrayList<User>();
		try{
			users = this.dao.findUser();
		}catch(Exception e){
			throw e;
		}finally{
			this.dbc.close();
		}
		return users;
	}

	public User findUser(String id) throws Exception {
		User user = new User();
		try{
			user = this.dao.findUser(id);
		}catch(Exception e){
			throw e;
		}finally{
			this.dbc.close();
		}
		return user;
	}

	public boolean addUser(User user) throws Exception {
		boolean flag = false;
		try{
			flag = this.dao.addUser(user);
		}catch(Exception e){
			throw e;
		}finally{
			this.dbc.close();
		}
		return flag;
	}

	public boolean deleteUser(User user) throws Exception {
		boolean flag = false;
		try{
			flag = this.dao.deleteUser(user);
		}catch(Exception e){
			throw e;
		}finally{
			this.dbc.close();
		}
		return flag;
	}

	
	
	

}
